const Bpmn = require('bpmn-engine');
const EventEmitter = require('events').EventEmitter;
let engine;
const activityIds = [];
const curNodeIds = [];
let callbackFun;
let dataCs;
let errCs;
function setListener() {
    const listener = new EventEmitter();
    listener.on('taken', (flow) => {
        activityIds.push(flow.id);
    });
    for (var i = 0; i < dataCs['nodeIds'].length; i++) {
        listener.once('wait-' + dataCs['nodeIds'][i], (child, instance) => {
            activityIds.push(child.activity.id);
            instance.signal(child.activity.id, {
                sirname: 's'
            });
        });
    }
    return listener;
}
setTimeout(() => {
    callbackFun(errCs, {activityIds: activityIds, curNodeIds: curNodeIds, state: engine.getState()});
}, 300);
return function (data, callback) {
    callbackFun = callback;
    dataCs = data;

    engine = Bpmn.Engine.resume(state, {
        variables: data.variables,
        listener: setListener()
    },  (err, definition) => {
        errCs = err;
        callbackFun(errCs, {activityIds: activityIds, curNodeIds: curNodeIds, state: ''});
    });
};